package com.restaurante.restauranteandroid.utils;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;

import android.widget.EditText;

public class Utils {
	
	public static boolean campoVazio(EditText campo){
		if ("".equals(campo.getText().toString())){
			return true;
		}
		return false;
	}
	
	public static String stringEditText(EditText campo){
		if (!Utils.campoVazio(campo)){
			return campo.getText().toString();
		}
			return "";
		
	}
	
	public static String formatValueDecimal(final String value) throws IllegalArgumentException {
		
		String valueAux = value.replace(",","");
		valueAux = valueAux.replace(".","");
		if (value.isEmpty()) {
			valueAux = "0";
		}
		BigDecimal bigDecimalValue = new BigDecimal(valueAux);  
		DecimalFormat df = new DecimalFormat("#,##0.00", new DecimalFormatSymbols(new Locale("pt","BR")));  
		String s = df.format(bigDecimalValue.divide(new BigDecimal("100.00")));  
		return s;
	}
	
	
}